import java.util.Scanner;

public class test {
    public static void main(String[] args) {
        Scanner scanner=new Scanner(System.in);
        int n= scanner.nextInt();
        int m= scanner.nextInt();
        int c=n%m;
        while(c!=0){
            n=m;
            m=c;
            c=n%m;
        }
        System.out.println(m);
    }
}
